package com.example.jpandroidtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;

import com.jpandroid.core.EntityManager;
import com.jpandroid.core.EntityManagerCore;
import com.jpandroid.database.DatabaseManager;

public class MainActivity extends Activity
{
	private EntityManager mEntityManager;
	private DatabaseManager mDatabaseManager;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mDatabaseManager = new DatabaseManager(this, new Class<?>[]{City.class, Person.class});
		mEntityManager = EntityManagerCore.getInstance(mDatabaseManager);
		
		test();
	}

	private void test()
	{
		City city = new City("abc", "cba", 1);
		city = (City) mEntityManager.insert(city);
		
		Person person = new Person("Test", city);
		person = (Person) mEntityManager.insert(person);
		
		Toast.makeText(this, person.getName(), Toast.LENGTH_SHORT).show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
